package cn.iocoder.yudao.module.iot.dal.mysql.devicerel;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.iot.dal.dataobject.devicerel.DeviceRelDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.warnpolicy.WarnPolicyDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.iot.controller.admin.devicerel.vo.*;

/**
 * 报警器和气阀绑定 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface DeviceRelMapper extends BaseMapperX<DeviceRelDO> {

    default PageResult<DeviceRelDO> selectPage(DeviceRelPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceRelDO>()
                .likeIfPresent(DeviceRelDO::getDeviceName, reqVO.getDeviceName())
                .likeIfPresent(DeviceRelDO::getValveCode, reqVO.getValveCode())
                .betweenIfPresent(DeviceRelDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(DeviceRelDO::getActive, reqVO.getActive())
                .betweenIfPresent(DeviceRelDO::getActiveTime, reqVO.getActiveTime())
                .eqIfPresent(DeviceRelDO::getMemberId, reqVO.getMemberId())
                .eqIfPresent(DeviceRelDO::getErrorFlag, reqVO.getErrorFlag())
                .eqIfPresent(DeviceRelDO::getNoticeType, reqVO.getNoticeType())
                .orderByDesc(DeviceRelDO::getId));
    }


    default DeviceRelDO getDeviceRelByDeviceName(String deviceName) {
        return selectOne(DeviceRelDO::getDeviceName, deviceName);
    }

    default Long getDeviceCountByDeviceName(String deviceName) {
        return selectCount(DeviceRelDO::getDeviceName, deviceName);
    }

    default Long getDeviceCountByvalveCode(String valveCode) {
        return selectCount(DeviceRelDO::getValveCode, valveCode);
    }

    default DeviceRelDO getDeviceRelByvalveCode(String valveCode) {
        return selectOne(DeviceRelDO::getValveCode, valveCode);
    }

}